home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / bool < prev    next >
Text File  |  1996-07-18  |  3KB  |  99 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8.  
  9. -- bool.sa: Boolean values.
  10. -------------------------------------------------------------------
  11. immutable class BOOL < $STR, $IS_EQ, $FMT is
  12.    -- BOOL objects represent boolean values and are either equal to 
  13.    -- `true' or `false'. The boolean operators `and' and `or' are 
  14.    -- part of the Sather language. This class defines several 
  15.    -- additional operators.
  16.    include COMPARABLE;
  17.    
  18.    not:SAME is
  19.       -- The complement of self.
  20.       -- if self then return false else return true end 
  21.       builtin BOOL_NOT; end;
  22.    
  23.    xnor(b:SAME):SAME is
  24.       -- True if self and `b' have the same value (same as "is_eq").
  25.       builtin BOOL_IS_EQ; end;
  26.    
  27.    is_eq(b:SAME):SAME is
  28.       -- True if self and `b' have the same value (same as "xnor").
  29.       builtin BOOL_IS_EQ; end;
  30.    
  31.    xor(b:SAME):SAME is
  32.       -- Self exclusive ored with `b'.  Same as "/=".
  33.       return self/=b end;
  34.    
  35.    nand(b:SAME):SAME is
  36.       -- The complement of self anded with `b'.
  37.       return ~(self and b) end;
  38.    
  39.    nor(b:SAME):SAME is
  40.       -- The complement of self ored with `b'.
  41.       return ~(self or b) end;
  42.    
  43.    implies(b:SAME):SAME is
  44.       -- True iff self implies `b'. Same as "nand_not".
  45.       return not or b end;
  46.    
  47.    and_rout(b:SAME):SAME is
  48.       -- A routine version of "self and `b'". (Useful for making
  49.       -- bound routines.)
  50.       return self and b end;
  51.    
  52.    or_rout(b:SAME):SAME is
  53.       -- A routine version of "self or `b'". (Useful for making
  54.       -- bound routines.)
  55.       return self or b end;   
  56.  
  57.    and_not(b:SAME):SAME is
  58.       -- Computes self and the complement of `b'.
  59.       return self and ~b end;
  60.  
  61.    or_not(b:SAME):SAME is
  62.       -- Computes self or the complement of `b'.
  63.       return self or ~b end;
  64.    
  65.    nand_not(b:SAME):SAME is
  66.       -- Computes self nand the complement of `b'. This is the same as
  67.       -- the complement of self or `b'.
  68.       return not or b end;
  69.  
  70.    nor_not(b:SAME):SAME is
  71.       -- Computes self nor the complement of `b'. This is the same as
  72.       -- the complement of self and `b'.
  73.       return not and b end;
  74.    
  75.    int:INT is
  76.       -- 0 for false, 1 for true
  77.       builtin BOOL_INT; end;
  78.    
  79.    str:STR is
  80.       -- The string representation of self.
  81.       if self then return "true" else return "false" end end;
  82.  
  83.    fmt( f: STR ):STR
  84.    is
  85.       return BASE_FORMAT::fmt_bool( self, f )
  86.    end;
  87.    
  88.    from_str(s:STR):SAME is
  89.        case s
  90.        when "true","t","True","T","TRUE" then return true;
  91.        when "false","f","False","F","FALSE" then return false;
  92.        else raise "Can't interpret bool value: "+s;
  93.        end;
  94.    end;
  95.  
  96. end; -- immutable class BOOL
  97.  
  98. -------------------------------------------------------------------
  99.